<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="会员名称" prop="username">
        <el-input
          v-model="queryParams.username"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" stripe border max-height="600" style="width: 100%">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="uid" align="center" prop="uid" width="160" />
      <el-table-column label="头像" align="center" prop="avatar" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <img :src="scope.row.avatar"  width="60" height="60" />
        </template>
      </el-table-column>
      <el-table-column label="会员名称" align="center" prop="consignee" width="160" />
      <el-table-column label="手机号码" align="center" prop="phone" width="150" />
      <el-table-column label="电子邮箱" align="center" prop="email" width="150" />
      <el-table-column label="性别" align="center" prop="gender" :formatter="genderFormat" />
      <el-table-column label="所在地" align="center" prop="totalNum" />
      <el-table-column label="注册时间" align="center" prop="createTime" width="180" />
      <el-table-column label="修改人" align="center" prop="updateBy" width="60"/>
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { listMember } from "@/api/member/member";

  export default {
    name: "MemberList",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 表格数据
        list: [],
        // 状态
        genderOptions: [],
        // 查询参数
        queryParams: {
          page: 1,
          size: 20,
          username: undefined,
          phone: undefined
        }
      };
    },
    created() {
      this.getList();
      this.getOptions("gender").then(response => {
        this.genderOptions = response.data.options;
      });
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true;
        listMember(this.queryParams).then(response => {
            this.list = response.data.rows;
            this.total = response.data.total;
            this.loading = false;
          }
        );
      },
      // 状态翻译
      genderFormat(row, column) {
        return this.selectOptionValue(this.genderOptions, row.gender);
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.createTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      }
    }
  };
</script>
